// let hint = [4, 1, 1, 1];
// let actual = [1, 1, 1, 1, 0, 1, 0, 1, 0, 1];
let hint = [1, 1, 1];
let actual = [0, 1, 0, 1, 0, 0, 0, 0, 0, 0];

const clone = obj => (JSON.parse(JSON.stringify(obj)));

let backup = clone(actual);
let _hint = clone(hint);

let count = 0;
let zeroCount = 0;
let offset = 0;

let deal = () => {
    if (hint.length <= 0) {
        return;
    }
    console.log(actual, hint);
    for (let i = 0; i < actual.length; i++) {
        let flag = true;
        switch (actual[i]) {
            case -1:
                if (count > 0) {
                    count = 0;
                    actual = actual.slice(i);
                    offset += i;
                    hint.shift()
                }
                break;
            case 0:
                if (count === 0) {
                    // zeroCount++;
                    flag = false;
                } else {
                    if (count < hint[0]) {
                        actual[i] = 1;
                        backup[i + offset] = 1;
                        count++;
                    } else {
                        actual[i] = -1;
                        backup[i + offset] = -1;
                        count = 0;
                        actual = actual.slice(i);
                        offset += i;
                        hint.shift();
                    }
                }
                break;
            case 1:
                count++;
                break;
            default:
                break;
        }

        if (!flag) {
            break;
        }
    }
}

let deal2 = () => {
    if (hint.length <= 0) {
        return;
    }
    console.log(actual, hint);
    count = 0;
    for (let i = 0; i < actual.length; i++) {
        let flag = true;
        switch (actual[i]) {
            case -1:
                if (zeroCount > 0) {
                    if (hint[0] > zeroCount) {
                        for (let i = 0; i < zeroCount; i++){
                            actual[i] = -1;
                        }
                    }
                    flag = false;
                }
                // start predict
                break;
            case 0:
                if (count === 0) {
                    zeroCount++;
                } else {
                    // start predict
                    flag = false;
                }
                break;
            case 1:
                if (zeroCount > 0) {
                    count++;
                }
                break;
            default:
                break;
        }

        if (!flag) {
            break;
        }
    }
}

for (let i = 0; i < 10; i++) {
    deal()
    deal2()
}

    console.log(backup.join(' '))
